/*
 * @Author: ljc
 * @Date: 2023-04-06 17:22:53
 * @LastEditors: g05047
 * @LastEditTime: 2023-06-30 16:17:58
 * @Description: 上传文档接口
 */

import { defAxios as request } from '@/utils/http'
import { decryptAxios as decryptRequest } from '@/utils/http'

export function useFileApi() {
    return {
        uploadFileRuleData,
        delUploadFileData,
        previewFileData,
        downloadSzysTemplate,
        downloadFileData,
        downloadReportData,
        downloadData,
        onlineReviewData,
        uploadSzysFile,
        getAllUploadFiles,
        getOnlineUploadFiles
    }
}

/**
 * 获取附件规则
 *
 * @returns Proxy
 */
function uploadFileRuleData(params) {
    return request({
        url: '/uploadFile/rule',
        method: 'post',
        data: params
    })
}

/**
 * 删除附件规则
 *
 * @returns Proxy
 */
function delUploadFileData(fileId) {
    return request({
        url: `/uploadFile/delete/${fileId}`,
        method: 'post',
        data: {}
    })
}

/**
 * 预览文件
 * @returns Proxy
 */
 function previewFileData(fileId) {
    return request({
        url: `/uploadFile/preview/${fileId}`,
        method: 'post',
        responseType: "blob",
        // headers: {
        //     "Content-Type": "application/pdf",
        // },
    })
}

function downloadSzysTemplate() {
    return request({
        url: `/proResApply/szysTemplateDownLoad`,
        method: 'get',
        responseType: "blob",
    })
}

/**
 * 下载文件
 *
 * @returns Proxy
 */
function downloadFileData(fileId) {
    return request({
        url: `/uploadFile/download/${fileId}`,
        method: 'post',
        responseType: "blob",
        headers: {
            "Content-Type": "application/x-www-form-urlencoded;charset=UTF-8",
        },
    })
}
/**
 * 下载文件项目专家评审
 *
 * @returns Proxy
 */
function downloadReportData(params) {
    return request({
        url: '/onlineReview/downloadReport',
        method: 'post',
        responseType: "blob",
        data: params,
    })
}


function downloadData(params, progressFunc) {
    return request({
        url: '/onlineReview/download',
        method: 'post',
        responseType: "blob",
        data: params,
        onDownloadProgress: progressFunc
    })
}
/**
 * 预览文件项目专家评审
 *
 * @returns Proxy
 */
function onlineReviewData(params) {
    return request({
        url: '/onlineReview/previewReport',
        method: 'post',
        responseType: "blob",
        data: params,
    })
}


function uploadSzysFile(data) {
    return decryptRequest({
        url: '/proResApply/parse',
        method: 'post',
        data: data,
        headers: {
            'Content-Type': 'multipart/form-data;'
        }
    })
}

function getAllUploadFiles(params) {
    return request({
        url: '/uploadFile/list',
        method: 'post',
        data: params,
    })
}

function getOnlineUploadFiles(params) {
    return request({
        url: '/uploadFile/previewList',
        method: 'post',
        data: params,
    })
}
